package com.zoweunion.mechanic.dao.base;

import com.zoweunion.mechanic.sqlprovider.KanBanSqlProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

public interface KanBanDao {

	@Select("select *,T_S_SS_USER.user_name from t_s_tt_order left join T_S_SS_USER on t_s_tt_order.u_s_id = T_S_SS_USER.id where t_s_tt_order.delete_flag = 0 and t_s_tt_order.s_id = #{s_id}")
	List<Map<String, Object>> getOrderInfoList(Map<String, Object> reqMap);
	 
	@SelectProvider(type=KanBanSqlProvider.class,method="getTotalCount")
	int getTotalCount();

	@SelectProvider(type=KanBanSqlProvider.class,method="getDongLiCount")
	int getDongLiCount(@Param("dictionaries_name_dl") String dictionaries_name_dl);

	@SelectProvider(type=KanBanSqlProvider.class,method="getYeYaCount")
	int getYeYaCount(@Param("dictionaries_name_ya") String dictionaries_name_ya);

	@SelectProvider(type=KanBanSqlProvider.class,method="getDianQiCount")
	int getDianQiCount(@Param("dictionaries_name_dq") String dictionaries_name_dq);

	@SelectProvider(type=KanBanSqlProvider.class,method="getGongZuoCount")
	int getGongZuoCount(@Param("dictionaries_name_gz") String dictionaries_name_gz);
	
	@SelectProvider(type=KanBanSqlProvider.class,method="getXingZouCount")
	int getXingZouCount(@Param("dictionaries_name_xz") String dictionaries_name_xz);
	
	@SelectProvider(type=KanBanSqlProvider.class,method="getQiTaCount")
	int getQiTaCount(@Param("dictionaries_name_qt") String dictionaries_name_qt);

	@Select("select * from T_S_BR_ORDER_DETAIL_PARTS where delete_flag = 0 and s_id = #{s_id}")
	List<Map<String, Object>> getOrderInfoAndPartInfo(Map<String, Object> reqMap);

	@Select("SELECT t1.order_creat_time,t2.handle_time FROM t_s_tt_order t1 inner join   t_s_order_detail t2 ON t2.order_id=t1.id AND t2.order_status = 14 WHERE  t1.s_id = #{s_id} AND  t1.delete_flag = 0 ")
	List<Map<String, Object>> getOrderTimeInfo(Map<String, Object> reqMap);

	@Select("select T_S_TT_ORDER.*,T_S_ORDER_DETAIL.handle_time from T_S_TT_ORDER left join T_S_ORDER_DETAIL on T_S_ORDER_DETAIL.order_id = T_S_TT_ORDER.id INNER JOIN t_s_br_order_detail_repairman ON T_S_TT_ORDER.ID = t_s_br_order_detail_repairman.order_id where T_S_TT_ORDER.delete_flag = 0 and T_S_TT_ORDER.s_id = #{s_id} and t_s_br_order_detail_repairman.u_id = #{u_id}")
//	@Select("select tso.*,tsod.handle_time from T_S_TT_ORDER tso left join T_S_ORDER_DETAIL tsod on tsod.order_id = tso.id INNER JOIN t_s_br_order_detail_repairman tsbo ON tso.ID = tsbo.order_id where tso.delete_flag = 0 and tso.s_id = #{s_id} and tsbo.u_id = #{u_id} and tsod.order_status =#{tsod_status}")
	List<Map<String, Object>> getOrderInfoListByXgId(Map<String, Object> reqMap);

	@Select("select T_S_BD_CAR.* ,T_S_SS_USER.user_name from T_S_BD_CAR Left join t_s_br_owner_car on T_S_BD_CAR.id = t_s_br_owner_car.c_id left join T_S_SS_USER on t_s_br_owner_car.o_id = T_S_SS_USER.id where T_S_BD_CAR.delete_flag = 0 and T_S_BD_CAR.s_id = #{s_id}")
	List<Map<String, Object>> getCarInfoList(Map<String, Object> reqMap);
	
	@Select("select * from T_S_BD_UPKEEP where T_S_BD_UPKEEP.delete_flag = 0 and T_S_BD_UPKEEP.s_id = #{s_id}")
	List<Map<String, Object>> getUpkeepInfoList(Map<String, Object> reqMap);
	
	@Select("select * from t_s_ss_server WHERE id = #{s_id} and delete_flag = 0")		
	Map<String, Object> getServerInfoBySId(Map<String, Object> reqMap);

	@Select("select tsbu.quantity,tsp.dictionaries_name,tsp.dictionaries_model from T_S_BR_UPKEEP_DICTIONARIES tsbu LEFT JOIN T_SS_PARTS tsp ON tsbu.d_id = tsp.ID WHERE tsbu.u_id=#{upkeep_dictionaries_id} and tsbu.delete_flag = 0 and tsbu.s_id = #{s_id}")
	List<Map<String, Object>> getUpkeepDictionariesInfo(Map<String, Object> reqMap);

//	@Select("select T_S_BR_ORDER_DETAIL_PARTS.* from T_S_BR_ORDER_DETAIL_PARTS LEFT JOIN T_SS_PARTS ON T_S_BR_ORDER_DETAIL_PARTS.p_id = T_SS_PARTS.ID WHERE T_S_BR_ORDER_DETAIL_PARTS.delete_flag = 0 and T_S_BR_ORDER_DETAIL_PARTS.s_id = #{s_id}")
   @Select("select T_S_BR_ORDER_DETAIL_PARTS.* from T_S_BR_ORDER_DETAIL_PARTS  WHERE T_S_BR_ORDER_DETAIL_PARTS.delete_flag = 0 and T_S_BR_ORDER_DETAIL_PARTS.s_id = #{s_id}")
	List<Map<String, Object>> getOrderdetailPartsInfoList(Map<String, Object> reqMap);

	@Select("select T_S_TT_ORDER.id,appraise_context,appraise_time,user_name,mobile_phone,appraise_productivity,appraise_manner,appraise_result from T_S_TT_ORDER left join T_S_SS_USER on T_S_TT_ORDER.o_id = T_S_SS_USER.id where T_S_TT_ORDER.delete_flag = 0 and T_S_TT_ORDER.s_id = #{s_id} and order_status = 18")
	List<Map<String, Object>> getChaPingInfo(Map<String, Object> reqMap);

	@Select("select T_SS_DICTIONARIES.dictionaries_type,T_SS_DICTIONARIES.dictionaries_name ,t_s_bd_car.car_type from T_S_BR_ORDER_DETAIL_FAULT left join T_SS_DICTIONARIES on T_S_BR_ORDER_DETAIL_FAULT.fault_id = T_SS_DICTIONARIES.id Left join t_s_tt_order on T_S_BR_ORDER_DETAIL_FAULT.order_id = t_s_tt_order.id left join T_S_BD_CAR on t_s_tt_order.c_id = T_S_BD_CAR.id WHERE T_S_BR_ORDER_DETAIL_FAULT.delete_flag = 0 and T_S_BR_ORDER_DETAIL_FAULT.s_id = #{s_id}")		
	List<Map<String, Object>> getDictionariesInfo(Map<String, Object> reqMap);

	@Select("select tu.user_name,tu.mobile_phone,tc.o_id as car_ower_id from t_s_br_owner_car tc left join t_s_ss_user tu on tc.o_id = tu.id WHERE tc.delete_flag=0 and tc.s_id =  #{s_id} GROUP BY tc.o_id,tu.user_name,tu.mobile_phone")
	List<Map<String, Object>> getContactInfo(Map<String, Object> reqMap);

	@Select("select order_type,payment_amount from T_S_TT_ORDER WHERE o_id = #{car_ower_id} and s_id = #{s_id} and delete_flag = 0")		
	List<Map<String, Object>> getOrderInfoByCarOwerId(Map<String, Object> reqMap);

	@Select("select tto.*,tu.user_name from t_s_tt_order tto left join T_S_SS_USER tu on tto.u_t_id = tu.id where tto.delete_flag = 0 and tto.s_id = #{s_id} and tu.r_id=#{r_id}")
	List<Map<String, Object>> getOrderInfoList1(Map<String, Object> reqMap);

	@Select("select tsbr.* ,tu.user_name from t_s_br_order_detail_repairman tsbr left join T_S_SS_USER tu on tu.id = tsbr.u_id left join T_S_TT_ORDER tso on tso.id = tsbr.order_id WHERE tso.s_id =  #{s_id} and tsbr.delete_flag = 0")
	List<Map<String, Object>> getOrderAndRepairInfoList(Map<String, Object> reqMap);

	@Select("select handle_time from t_s_order_detail WHERE order_id = #{id} and delete_flag = 0 and order_status = #{order_status} LIMIT 1")
	String findStartHandTimeByIdAndOrderstatus(@Param("id") String id, @Param("order_status") int order_status);


	Map<String, Object> getOrderInfo(String parent_id);

	@Select("select tso.*,tu.user_name from t_s_tt_order tso left join T_S_SS_USER tu on tso.u_s_id = tu.id where tso.delete_flag = 0 and tso.s_id = #{s_id} and tso.create_time >= date_add(now(), interval -7 day)")
	List<Map<String, Object>> getToDayOrderInfoList(Map<String, Object> reqMap);

	int getCarCount(String o_id);

	List<Map<String, Object>> getCountOrderInfoList(Map<String, Object> reqMap);

	List<Map<String, Object>> getOrderAndStatusList(Map<String, Object> reqMap);

	List<Map<String, Object>> getOrderInfoByCarOwerIdTo(@Param("o_id") String o_id);

	@Select("select tso.*,tsod.handle_time,tsbo.u_type from T_S_TT_ORDER tso left join T_S_ORDER_DETAIL tsod on tsod.order_id = tso.id left join t_s_br_order_detail_repairman tsbo ON tso.ID = tsbo.order_id where tso.delete_flag = 0 and tso.s_id = #{s_id} and tsbo.u_id = #{u_id} and tsod.order_status =#{tsod_status} and tso.order_status = 18 ")
	List<Map<String, Object>> getOrderInfoListByXgIdAndStatus(Map<String, Object> reqMap);

	List<Map<String, Object>> getXgListInfo(Map<String, Object> reqMap);

	@Select("select *,T_S_SS_USER.user_name from t_s_tt_order left join T_S_SS_USER on t_s_tt_order.u_cg_id = T_S_SS_USER.id where t_s_tt_order.delete_flag = 0 and t_s_tt_order.s_id = #{s_id}")
	List<Map<String, Object>> getOrderInfoListByCG(Map<String, Object> reqMap);


	List<Map<String, Object>> getOrderdetailPartsInfoListT(Map<String, Object> reqMap);

	List<Map<String, Object>> getCutPartsInfoList(Map<String, Object> reqMap);

    List<Map<String, Object>> workOrderAmount(Map<String, Object> reqMap);

	Object workOrderTotalSum(Map<String, Object> reqMap);

	List<Map<String, Object>> repairAmount(Map<String, Object> reqMap);

	Map<String, Object> workOrderCount(Map<String, Object> reqMap);

    List<Map<String, Object>> repairCount(Map<String, Object> reqMap);
}
